package com.gitee.feizns.quickstart.ding.talk.api.top.api.role;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRoleGetrolegroupRequest;
import com.dingtalk.api.response.OapiRoleGetrolegroupResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 获取角色组
 * @author feizns
 * @since 2025/3/24
 */
public class GetRoleGroup {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param groupId 群编号
     * @return {@link OapiRoleGetrolegroupResponse.OpenRoleGroup }
     */
    @SneakyThrows
    public static OapiRoleGetrolegroupResponse.OpenRoleGroup execute(String accessToken, Long groupId) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/getrolegroup");
        OapiRoleGetrolegroupRequest req = new OapiRoleGetrolegroupRequest();
        req.setGroupId(groupId);
        OapiRoleGetrolegroupResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getRoleGroup();
    }

}
